//
//  XQPositionThreeTableViewCell.swift
//  XiaoQiQiaoSwift
//
//  Created by tech-lab on 2016/11/29.
//  Copyright © 2016年 校企桥. All rights reserved.
//

import UIKit

class XQPositionThreeTableViewCell: UITableViewCell {
    
    var icon = UIImageView()
    var titleLabel = UILabel()
    var companyLabel = UILabel()
    var typeLabel = UILabel()
    var salaryLabel = UILabel()
    var cityLabel = UILabel()
    var timeLabel = UILabel()
    
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        InitUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    var positionMode:XQHomePositionMode?{
        didSet{
            let url = URL.init(string: (positionMode?.logo)!)
            icon.kf.setImage(with: url)
            
            titleLabel.text = positionMode?.position_name
            typeLabel.text = positionMode?.position_type
            companyLabel.text = positionMode?.company_name
            salaryLabel.text = positionMode?.salary
            cityLabel.text = positionMode?.area_id
            timeLabel.text = positionMode?.c_time
        }
    }
    
    
    func InitUI()  {
        
        icon = UIImageView.init(frame: CGRect.zero)
        self.contentView .addSubview(icon)
        
        titleLabel = UILabel.init(frame: CGRect.zero)
        self.contentView .addSubview(titleLabel)
        
        companyLabel = UILabel.init(frame: CGRect.zero)
        companyLabel.textColor = UIColor.lightGray
        companyLabel.font = UIFont.systemFont(ofSize: 14)
        self.contentView .addSubview(companyLabel)
        
        typeLabel = UILabel.init(frame: CGRect.zero)
        typeLabel.textColor = UIColor.orange
        typeLabel.font = UIFont.systemFont(ofSize: 12)
        self.contentView .addSubview(typeLabel)
        
        salaryLabel = UILabel.init(frame: CGRect.zero)
        salaryLabel.textColor = UIColor.orange
        salaryLabel.font = UIFont.systemFont(ofSize: 14)
        self.contentView.addSubview(salaryLabel)
        
        cityLabel = UILabel.init(frame: CGRect.zero)
        cityLabel.font = UIFont.systemFont(ofSize: 14)
        self.contentView.addSubview(cityLabel)
        
        timeLabel = UILabel.init(frame: CGRect.zero)
        timeLabel.font = UIFont.systemFont(ofSize: 14)
        self.contentView.addSubview(timeLabel)

        
        
        icon.snp.makeConstraints { (make) in
            make.left.equalTo(self.contentView.snp.left).offset(5)
            make.top.equalTo(self.contentView.snp.top).offset(10)
            make.width.equalTo(60)
            make.height.equalTo(60)
        }
        
        titleLabel.snp.makeConstraints { (make) in
            make.left.equalTo(icon.snp.right).offset(5)
            make.top.equalTo(self.contentView.snp.top).offset(10)
        }
        
        typeLabel.snp.makeConstraints { (make) in
            make.top.equalTo(self.contentView.snp.top).offset(10)
            make.right.equalTo(self.contentView.snp.right).offset(-5)
        }
        
        companyLabel.snp.makeConstraints { (make) in
            make.centerY.equalTo(self.contentView.snp.centerY)
            make.left.equalTo(icon.snp.right).offset(5)
        }
        
        salaryLabel.snp.makeConstraints { (make) in
            make.left.equalTo(icon.snp.right).offset(5)
            make.bottom.equalTo(icon.snp.bottom)
        }
        
        let line = UIView.init(frame: CGRect.zero)
        line.backgroundColor = UIColor.lightGray
        self.contentView.addSubview(line)
        
        line.snp.makeConstraints { (make) in
            make.left.equalTo(salaryLabel.snp.right).offset(2)
            make.width.equalTo(0.5)
            make.height.equalTo(15)
            make.centerY.equalTo(salaryLabel.snp.centerY)
        }

        cityLabel.snp.makeConstraints { (make) in
            make.left.equalTo(line.snp.right).offset(3)
            make.bottom.equalTo(icon.snp.bottom)
        }
        
        timeLabel.snp.makeConstraints { (make) in
            make.right.equalTo(self.contentView.snp.right).offset(-5)
            make.bottom.equalTo(icon.snp.bottom)
        }
        
    }

}
